﻿using System;

namespace DataAchive.Helper
{
    public class ActivatorHelper
    {

        /// <summary>
        /// 静态方法用于获取单例实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public static T GetInstance<T>(ref T t)
        {
            if (t == null)
            {
                t = (T)Activator.CreateInstance(typeof(T));
            }
            return t;
        }

        /// <summary>
        /// 静态方法用于获取单例实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public static T GetInstance<T>(ref T t, object[] paramerters)
        {
            if (t == null)
            {
                t = (T)Activator.CreateInstance(typeof(T), paramerters);
            }
            return t;
        }
    }
}
